package com.easylinkin.linkappapi.circuit.controller;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.circuit.dto.RailGiveAlarmTypeConfigDTO;
import com.easylinkin.linkappapi.circuit.entity.RailGiveAlarmTypeConfig;
import com.easylinkin.linkappapi.circuit.service.IRailGiveAlarmTypeConfigService;
import com.easylinkin.linkappapi.circuit.vo.RailGiveAlarmTypeConfigVO;
import com.easylinkin.linkappapi.common.model.RequestModel;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import javax.annotation.Resource;
import java.util.List;

/**
 * 系统告警类型接口类
 * @author lyk
 * @date 2025/6/17 下午 1:51
 */
@RestController
@RequestMapping("/giveAlarmTypeConfig")
public class RailGiveAlarmTypeConfigController {
    @Resource
    private IRailGiveAlarmTypeConfigService railGiveAlarmTypeConfigService;
    /**
     * 分页查询
     * @param requestModel
     * @return
     */
    @PostMapping("/getPage")
    public RestMessage selectPage(@RequestBody RequestModel<RailGiveAlarmTypeConfigDTO> requestModel) {
        Assert.notNull(requestModel.getPage(), "page 不能为空");
        IPage<RailGiveAlarmTypeConfigVO> record = railGiveAlarmTypeConfigService.selectPage(requestModel.getPage(), requestModel.getCustomQueryParams());
        return RestBuilders.successBuilder(record).build();
    }

    /**
     * 列表查询
     * @param requestModel
     * @return
     */
    @PostMapping("/selectList")
    public RestMessage selectList(@RequestBody RailGiveAlarmTypeConfigDTO requestModel) {
        List<RailGiveAlarmTypeConfigVO> record = railGiveAlarmTypeConfigService.selectList(requestModel);
        return RestBuilders.successBuilder(record).build();
    }

    /**
     * 批量保存设置
     *
     * @param recordList
     * @return
     */
    @PostMapping("/saveBatch")
    public RestMessage saveBatch(@RequestBody List<RailGiveAlarmTypeConfig> recordList) {
        railGiveAlarmTypeConfigService.addOrEditBatch(recordList);
        return RestBuilders.successBuilder().build();
    }

    /**
     * 查询计划值
     * @param requestModel
     * @return
     */
    @PostMapping("/planValue")
    public RestMessage planValue(@RequestBody RailGiveAlarmTypeConfigDTO requestModel) {
        List<RailGiveAlarmTypeConfigVO> record = railGiveAlarmTypeConfigService.planValue(requestModel);
        return RestBuilders.successBuilder(record).build();
    }
}
